package com.ikingtech.platform.service.attachment.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ikingtech.framework.sdk.attachment.model.AttachmentQueryParamDTO;
import com.ikingtech.framework.sdk.base.model.PageResult;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ikingtech.framework.sdk.utils.Tools;
import com.ikingtech.platform.service.attachment.entity.AttachmentDO;
import com.ikingtech.platform.service.attachment.mapper.AttachmentMapper;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;

/**
 * @author tie yan
 */
@Service
@RequiredArgsConstructor
public class AttachmentService extends ServiceImpl<AttachmentMapper, AttachmentDO> {

    public Boolean exist(String id) {
        return this.baseMapper.exists(Wrappers.<AttachmentDO>lambdaQuery().eq(AttachmentDO::getId, id));
    }

    public PageResult<AttachmentDO> listPage(AttachmentQueryParamDTO queryParam) {
        return PageResult.build(this.page(new Page<>(queryParam.getPage(), queryParam.getRows()), Wrappers.<AttachmentDO>lambdaQuery()
                .in(Tools.Coll.isNotBlank(queryParam.getIds()), AttachmentDO::getId, queryParam.getIds())
                .like(Tools.Str.isNotBlank(queryParam.getBusinessId()), AttachmentDO::getBusinessId, queryParam.getBusinessId())
                .orderByDesc(AttachmentDO::getCreateTime)));
    }
}
